package com.shardingsphere.example.sharding;
/**
 * 范围分表策略
 */
public class RangeShardingStrategy implements ShardingStrategy {

    @Override
    public String getTableSuffix(Object shardingValue, int tableCount) {
        if (shardingValue == null) {
            return "0";
        }

        try {
            long value = Long.parseLong(shardingValue.toString());
            long rangeSize = 1000000L; // 每个表存储100万数据
            return String.valueOf((value / rangeSize) % tableCount);
        } catch (NumberFormatException e) {
            return "0";
        }
    }
}

